package com.example.Blog.dao;

import com.example.Blog.model.User;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

public interface UserDao extends JpaRepository<User, Integer> {
    User findByUserId(int userId);
    List<User> findByUserNicknameOrderByUserFans(String userName);

    @Modifying
    @Query("update User u set u.userFans = :userFans where u.userId = :userId")
    void updateByUserId(@Param("userFans") int userFans, @Param("userId") int userId);

    @Modifying
    @Query("update User u set u.userNickname = :userNickname where u.userId = :userId")
    void updateByUserId(@Param("userNickname") String userNickname, @Param("userId") int userId);

    @Modifying
    @Query("update User u set u.userPassword = :userPassword where u.userId = :userId")
    void updateUserByUserId(@Param("userPassword") String userPassword, @Param("userId") int userId);

    User findByUserNickname(String userNickname);

    User findByUserAccount(String userAccount);
}
